package org.csu.molediary.api.controller.back;


import org.csu.molediary.api.common.CommonResponse;
import org.csu.molediary.api.service.AdminSignOnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Controller
@RequestMapping("/adminForm/")
@SessionAttributes(value = {"adminname"})
public class AdminSignOnController {

    @Autowired
    private AdminSignOnService adminSignOnService;

    @GetMapping("login")
    @ResponseBody
    //管理员登录
    public CommonResponse<String> adminLogin(HttpServletRequest request,@RequestParam String adminname,@RequestParam String password){
        System.out.print("login");
        request.getSession().setAttribute("adminname",adminname);
        System.out.println(request.getSession().getAttribute("adminname"));
        request.getSession().setAttribute("password",password);
        return adminSignOnService.adminLogin(adminname,password);
    }

    @PostMapping("changepassword")
    @ResponseBody
    //管理员修改密码
    public CommonResponse<String> adminChangePassword(HttpServletRequest request,@RequestParam ("password")String password,@RequestParam ("newpassword")String newpassword){

        System.out.println("4444");
        String adminname=(String)request.getSession().getAttribute("adminname");
        System.out.println(adminname);
        return adminSignOnService.adminChangePassword(adminname,password,newpassword);
    }
}
